package com.ffcs.crmd.tsp.admin.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.ctg.itrdc.platform.common.entity.PageInfo;
import com.ffcs.crmd.tsp.admin.entity.JobDetailTrack;
import com.ffcs.crmd.tsp.admin.service.IJobDetailTrackService;
import com.ffcs.crmd.tsp.api.dto.client.TspJobDetailTrack;
import com.ffcs.crmd.tsp.api.dto.client.TspResult;
import com.ffcs.crmd.tsp.client.core.TspClient;
import com.ffcs.crmd.tsp.common.exception.TspException;
import com.ffcs.crmd.tsp.core.util.BeanUtils;

/**
 * 
 * 功能说明:子任务转移service
 *
 * @author ZHONGFUHUA
 * 
 * @Date 2015年10月20日 下午4:26:46
 *
 *
 * 版本号 | 作者 | 修改时间 | 修改内容
 *
 */
@Service
public class JobDetailTrackServiceImpl extends AbstractService implements IJobDetailTrackService{
    
    
    @Override
    public List<JobDetailTrack> query(JobDetailTrack jobDetailTrack) throws TspException {
        try {
            TspJobDetailTrack tspJobDetailDeathTrack = new TspJobDetailTrack();
            BeanUtils.applyIf(tspJobDetailDeathTrack, jobDetailTrack, false);
            
            TspClient tspClient = this.getClient(jobDetailTrack.getClusterName());
            TspResult<TspJobDetailTrack> tspResult = tspClient.queryJobDetailTrack(tspJobDetailDeathTrack);
            validateResult(tspResult);
            
            List<TspJobDetailTrack> tspJobDetailDeathVOList = new ArrayList<TspJobDetailTrack>();
            tspJobDetailDeathVOList.addAll(tspResult.getRetVo().getDataList());
            return BeanUtils.copyList(tspJobDetailDeathVOList, JobDetailTrack.class); 
        } catch (Exception e) {
            throw new TspException(e.getMessage());
        }
    }
    
    
    @Override
    public PageInfo<JobDetailTrack> queryPage(JobDetailTrack jobDetailTrack, int pageNumber, int pageSize) throws TspException {
        try {
            TspJobDetailTrack tspJobDetailDeathTrack = new TspJobDetailTrack();
            BeanUtils.applyIf(tspJobDetailDeathTrack, jobDetailTrack, false);
            tspJobDetailDeathTrack.setPageNumber(pageNumber);
            tspJobDetailDeathTrack.setPageSize(pageSize);
            
            TspClient tspClient = getClient(jobDetailTrack.getClusterName());
            TspResult<TspJobDetailTrack> tspResult = tspClient.queryJobDetailTrack(tspJobDetailDeathTrack);
            validateResult(tspResult);
            
            com.ffcs.crmd.tsp.api.dto.page.PageInfo<TspJobDetailTrack> tspJobDetailTrackPageInfo = tspResult.getRetVo().getPageInfo();
            PageInfo<JobDetailTrack> jobDetailTrackPageInfo = new PageInfo<JobDetailTrack>();
            BeanUtils.applyIf(jobDetailTrackPageInfo, tspResult.getRetVo().getPageInfo());
            jobDetailTrackPageInfo.setList(BeanUtils.copyList(tspJobDetailTrackPageInfo.getList(), JobDetailTrack.class));
            return  jobDetailTrackPageInfo;
        } catch (Exception e) {
            throw new TspException(e.getMessage());
        }
    }
    
}
